

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using JTC.MiniCommerce.Core;
using JTC.MiniCommerce.Localization;
using JTC.MiniCommerce.Store;
using JTC.MiniCommerce.Store.Services.MessageService;

namespace JTC.MiniCommerce.Web {
  public partial class passwordrecover : System.Web.UI.Page {

    #region Page Events

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e) {
      try {
        SetPasswordRecoverControlProperties();
        MailSettings mailSettings = MailSettings.Load();
        MailDefinition mailDefinition = prPasswordRecover.MailDefinition;
        mailDefinition.From = mailSettings.From;
      }
      catch(Exception ex) {
        Logger.Error("Page_Load", ex);
        throw;
      }
    }

    /// <summary>
    /// Handles the SendingMail event of the prPasswordRecover control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.Web.UI.WebControls.MailMessageEventArgs"/> instance containing the event data.</param>
    protected void prPasswordRecover_SendingMail(object sender, MailMessageEventArgs e) {
      try {
        MessageService messageService = new MessageService();
        messageService.Send(e.Message);
        e.Cancel = true;
      }
      catch(Exception ex) {
        Logger.Error("prPasswordRecover_SendingMail", ex);
      }
    }

    #endregion

    #region Methods

    #region Private

    /// <summary>
    /// Sets the password recover control properties.
    /// </summary>
    private void SetPasswordRecoverControlProperties() {
      prPasswordRecover.UserNameTitleText = LocalizationUtility.GetText("prPasswordRecoverUserNameTitleText");
      prPasswordRecover.UserNameInstructionText = LocalizationUtility.GetText("prPasswordRecoverUserNameInstructionText");
      prPasswordRecover.UserNameLabelText = LocalizationUtility.GetText("prPasswordRecoverUserNameLabelText");
      prPasswordRecover.UserNameFailureText = LocalizationUtility.GetText("prPasswordRecoverUserNameFailureText");
      prPasswordRecover.QuestionTitleText = LocalizationUtility.GetText("prPasswordRecoverQuestionTitleText");
      prPasswordRecover.QuestionInstructionText = LocalizationUtility.GetText("prPasswordRecoverQuestionInstructionText");
      prPasswordRecover.QuestionLabelText = LocalizationUtility.GetText("prPasswordRecoverQuestionLabelText");
      prPasswordRecover.QuestionFailureText = LocalizationUtility.GetText("prPasswordRecoverQuestionFailureText");
      prPasswordRecover.AnswerLabelText = LocalizationUtility.GetText("prPasswordRecoverAnswerLabelText");
      prPasswordRecover.SubmitButtonText = LocalizationUtility.GetText("prPasswordRecoverSubmitButtonText");
      prPasswordRecover.SuccessText = LocalizationUtility.GetText("prPasswordRecoverSuccessText");
    }

    #endregion

    #endregion

  }
}
